<template>
  <div>
    <div>
      <BreadX></BreadX>
    </div>
    <el-card style="margin-top: 30px">
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            clearable
            @clear="searchorder"
            @input="searchorder"
            v-model="orderlist.query"
            ><el-button slot="append" icon="el-icon-search"></el-button
          ></el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-table border style="margin-top: 15px" :data="ordersdata">
            <el-table-column type="index" label="#"></el-table-column>
            <el-table-column
              label="订单编号"
              prop="order_number"
              width="400px"
            ></el-table-column>
            <el-table-column
              label="订单价格"
              prop="order_price"
            ></el-table-column>
            <el-table-column label="是否付款" prop="pay_status">
              <template slot-scope="scope">
                <el-tag :type="pagleve[scope.row.pay_status]">{{
                  scope.row.pay_status | pay
                }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="是否发货" prop="is_send"></el-table-column>
            <el-table-column label="下单时间">
              <template slot-scope="scope">
                {{ scope.row.create_time | dateTime }}
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  icon="el-icon-edit"
                  size="mini"
                  @click="editdialog(scope.row.id)"
                ></el-button>
                <el-button
                  type="success"
                  icon="el-icon-location-outline"
                  size="mini"
                  @click="wuliutk(scope.row)"
                ></el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="orderlist.pagenum"
            :page-sizes="[2, 4, 6, 8]"
            :page-size="orderlist.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </el-card>
    <!-- 修改弹框 -->
    <el-dialog title="编辑" :visible.sync="dialogVisible">
      <el-form :model="ModiAddress">
        <el-form-item label="省市区/县" label-width="100px">
          <el-cascader 
            style="width:100%"
            clearable
            v-model="checkArr"
            :options="CityData"
            :props="defaultProps"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" label-width="100px">
          <el-input v-model="ModiAddress.city" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 查看物流进度 -->
    <el-dialog title="物流进度" :visible.sync="wuliudai">
      <el-timeline>
    <el-timeline-item
      v-for="(item, index) in Wuliu"
      :key="index"
      :icon="item.icon"
      :type="item.type"
      :color="item.color"
      :size="item.size"
      :timestamp="item.time">
      {{item.context}}
    </el-timeline-item>
  </el-timeline>



      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(item, index) in Wuliu"
          :key="index"
          :timestamp="item.time"
        >
          {{ item .context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wuliudai = false">取 消</el-button>
        <el-button type="primary" @click="wuliudai = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import CityData from "@/mock/city";
import Wuliu from "@/mock/wuliu"
import BreadX from "@/components/BreadX.vue";
import _ from "lodash";
export default {
  components: { BreadX },
  data() {
    return {
      wuliudai:false,
      Wuliu:Wuliu.data,
      reverse: false,
      checkArr: [],
      CityData: CityData,
      defaultProps: {
        expandTrigger: "hover",
        lable: "label",
        children: "children",
        value: "value",
      },
      ModiAddress: { city: "" },
      ordersdata: [],
      orderlist: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      pagleve: {
        0: "danger",
        1: "success",
      },
      dialogVisible: false,
    };
  },
  created() {
    this.getorders();
  },
  methods: {
    // 物流进度
    wuliutk(){
      this.wuliudai=true
      
    },
    // 编辑
    editdialog() {
      this.dialogVisible = true;
     
    },
    handleChange() {
      console.log("二级联动数据改变后触发");
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.orderlist.pagesize = val;
      this.getorders();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.orderlist.pagenum = val;
      this.getorders();
    },
    //   搜索
    searchorder: _.debounce(function () {
      this.getorders();
    }, 300),
    //   订单列表
    async getorders() {
      const res = await this.$API.ordersAPI(this.orderlist);
      console.log("订单管理", res);
      this.ordersdata = res.goods;
      this.total = res.total;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>